package com.eugene.ui.util;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;

// Referenced classes of package net.sourceforge.sqlexplorer.util:
//            URLUtil

public class ImageUtil {
	private static Map _imageCount = new HashMap();
	private static Map _images = new HashMap();

	
	public ImageUtil() {
	}

	public static void disposeImage(String propertyName) {
		Image image;
		image = (Image) _images.get(propertyName);
		if (image == null)
			return;
		try {
			Integer handleCount = (Integer) _imageCount.get(propertyName);
			if (handleCount == null || handleCount.intValue() == 0) {
				image.dispose();
				_images.remove(propertyName);
				_imageCount.remove(propertyName);
			} else {
				handleCount = new Integer(handleCount.intValue() - 1);
				_imageCount.put(propertyName, handleCount);
			}
		} catch (Throwable e) {
//			SQLExplorerPlugin.error("Error disposing images", e);
		}
		return;
	}

	public static ImageDescriptor getDescriptor(String propertyName) {
		if (propertyName == null)
			return null;
		String path;
//		path = Messages.getString(propertyName);
//		if (path != null && path.trim().length() != 0)
//			break MISSING_BLOCK_LABEL_47;
//		SQLExplorerPlugin.error((new StringBuilder("Missing image path for "))
//				.append(propertyName).toString(), null);
		return null;
//		try {
//			java.net.URL url = URLUtil.getResourceURL(path);
//			return ImageDescriptor.createFromURL(url);
//		} catch (Exception e) {
////			SQLExplorerPlugin.error((new StringBuilder(
////					"Couldn't create image for ")).append(propertyName)
////					.toString(), e);
//		}
//		return null;
	}

	public static ImageDescriptor getFragmentDescriptor(String fragmentId,
			String path) {
		if (path == null || path.trim().length() == 0)
			return null;
		try {
			java.net.URL url = URLUtil.getFragmentResourceURL(fragmentId, path);
			return ImageDescriptor.createFromURL(url);
		} catch (Exception e) {
//			SQLExplorerPlugin.error((new StringBuilder(
//					"Couldn't create image for ")).append(fragmentId).append(
//					": ").append(path).toString(), e);
		}
		return null;
	}

	public static Image getImage(String propertyName) {
		Image image = (Image) _images.get(propertyName);
		if (image == null) {
			image = getDescriptor(propertyName).createImage();
			if (image == null)
				return null;
			_images.put(propertyName, image);
		}
		Integer handleCount = (Integer) _imageCount.get(propertyName);
		if (handleCount == null)
			handleCount = new Integer(1);
		else
			handleCount = new Integer(handleCount.intValue() + 1);
		_imageCount.put(propertyName, handleCount);
		return image;
	}

	public static Image getFragmentImage(String fragmentId, String path) {
		if (path == null || path.trim().length() == 0)
			return null;
		ImageDescriptor descriptor;
		java.net.URL url = URLUtil.getFragmentResourceURL(fragmentId, path);
		descriptor = ImageDescriptor.createFromURL(url);
		if (descriptor == null)
			return null;
		try {
			return descriptor.createImage();
		} catch (Exception e) {
//			SQLExplorerPlugin.error((new StringBuilder(
//					"Couldn't create image for ")).append(fragmentId).append(
//					": ").append(path).toString(), e);
		}
		return null;
	}

	
}


/*
	DECOMPILATION REPORT

	Decompiled from: C:\Users\kidon\workspace\sqlexplorer/net/sourceforge/sqlexplorer/util/ImageUtil.class
	Total time: 20 ms
	Jad reported messages/errors:
Couldn't resolve all exception handlers in method disposeImage
Couldn't resolve all exception handlers in method getDescriptor
Couldn't resolve all exception handlers in method getFragmentDescriptor
Couldn't resolve all exception handlers in method getFragmentImage
	Exit status: 0
	Caught exceptions:
*/